import {createStore} from 'redux'
import {fromJS,Map} from 'immutable'

const intiastate=fromJS({
    name:"lx",
    age:23,
    address:{
        city:"武汉",
        region:"江夏"
    },
    hobbies:[
        {name:"javascript",desc:"是一种前端编程语言"},
        {name:"王者荣耀",desc:"一种流行手机游戏"}
    ]
})

function reducer(state=intiastate,action){
    switch(action.type){
        case "del":
          return state.update("hobbies",hobbies=>hobbies.filter(item=>item!==action.item))
        case "add":
          return state.update("hobbies",hobbies=>hobbies.push(Map(action.item)))
        default :
          return state
    }
}

export const store=createStore(reducer)